﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HelloLLLLL.Blog.Models;
using HelloLLLLL.Blog.DAL;
using System.Data;

namespace HelloLLLLL.Blog.html
{
    public partial class ArticleList : System.Web.UI.Page
    {
        public List<LLArticle> listAr;
        public List<LLType> listType;
        public int PageCount = 0;
        public int PageCurrent = 1;
        public string ArtType = "";

        public string RecordTime = "";

        public DataTable DtRecord;

        public List<LLArticle> ListRandom;

        DBHelper helper = new DBHelper();
        protected void Page_Load(object sender, EventArgs e)
        {
            //listAr = TestData.GetArticle();
            //GetListAr();
            PageCount = Convert.ToInt32(helper.GetScalar("select count(1) from LLArticle", null));
            listType = new ModelHandler<LLType>().FillModel(helper.GetDataTable("select * from LLArtType", null));
            ArtType = Request.QueryString["typeId"];
            RecordTime = Request.QueryString["recordTime"];
            GetRandom();
            GetRecord();
        }

        private void GetRandom()
        {
            string sql = @"	 select  [Id]
      ,[Title]
      ,[HomeImg]
      ,[Digest]
      ,[ArtTime]
      ,[LastUpdatetime]
      ,[Content]
      ,[ReadPwd]
      ,[Editor]
      ,[PresentCount]
      ,[CommentCount]
      ,[ReadCount]
      ,[IsTop] from ( select top 8 * ,newid() random  from LLArticle order by random)  as t";

        ListRandom = new ModelHandler<LLArticle>().FillModel(helper.GetDataTable(sql, null));
        }
      
        private void GetRecord()
        {
            string sql = @"SELECT COUNT(*) AS count,str(year(artTime))+str(month(artTime)) as ym FROM LLArticle GROUP BY str(year(artTime)) + str(month(artTime))";

            DtRecord = helper.GetDataTable(sql,null);
        }
    }
}